import tkinter as tk
win=tk.Tk()

varHeight = tk.StringVar()
#varHeight.set("")
import math
#s="5,10,8,12,6,17,"
#s="3,0,3,4,5,4,"
def click():
    
    s=txt.get()
    x1=y1=0
    k=1
    j=0
    totald=0
    for i in range(0,len(s)):
        if s[i]=="," :
            v=int(s[j:i])
            j=i+1
            if k % 2==1 :
                x2=v
            else:
                y2=v
                d=math.sqrt((x2-x1)**2+(y2-y1)**2)
                totald=totald+d
                x1=x2
                y1=y2
            k=k+1
    #lbl.insert(0,"折线长度为：" + str(totald))
    varHeight.set("折线长度为：" + str(totald))




win.title("计算折线长度")
win.geometry('320x100')
txt=tk.Entry(win)
lbl=tk.Label(win,textvariable=varHeight)#,textvariable="折线长度为："+varHeight)
cmd=tk.Button(win,text="计算",command=click)

#txt.grid(row=0,column=0,padx=30,pady=20)
#cmd.grid(row=0,column=1,padx=20)
#lbl.grid(row=1,column=0,padx=0)

txt.place(relx=0.1,rely=0.2)
cmd.place(relx=0.7,rely=0.15)
lbl.place(relx=0.1,rely=0.6)

win.mainloop()
